----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 48315 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 180
SPELL.m_sName = "Frost Punch"
SPELL.m_sToolTip = [[You pull a bomb from
					your pouch and slam it 
					into the target's face.]]
SPELL.m_sIcon = "devin/blackbetty/spells/brawler/icepunch.png"
SPELL.m_bRequiresTarget = true
SPELL.m_iCoolDown = 5
SPELL.m_iSpellType = SPELLTYPE_MELEEDAMAGE
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 10

function SPELL:Cast( pl, target )
	
	local target = nil
	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
		target = pl:GetNetworkedEntity("Target")
	else
		target = pl.Target
	end
	
	if(target && target:IsValid() && target != pl) then
		pl.InSpellAnimation = true
		ParticleEffectAttach( "frost_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
		pl:EmitSound("devin/blackbetty/weapons/castsounds/IceCast.wav", 150, 100+math.random(-10,-35))
		self.CastSound = CreateSound( pl, "devin/blackbetty/weapons/castingloops/Frost.wav" )
		self.CastSound:Play()
		pl.DoingCast = true
		pl.CastWhileMoving = true
		net.Start( "SendPlayerCast" )
		local SendTable = {0.5, self.m_sName, Color(0, 55, 255, 155)}
		net.WriteTable(SendTable)
		net.Send(pl)
		timer.Simple(0.5, function()
			pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE2)
			timer.Simple(0.2, function()
				pl:SetNWBool("Casting", false)
				pl:SetNWBool("Casted", false)
				pl.DoingCast = false
				self.CastSound:Stop()
				pl:StopParticles()
				target:EmitSound("devin/blackbetty/weapons/FrostNovaStateEnd.wav", 100, 100)
				target:EmitSound("devin/blackbetty/weapons/heroic_strike/heroic_strike.wav", 160, 100)
				if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
					if(SERVER)then
						timer.Simple(0.1, function() 
							ParticleEffect( "impact_frostbig", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), pl )
							local dmginfo = DamageInfo()
								dmginfo:SetDamage( math.Round(math.random(weapon.MinWeaponDamage*2.5, weapon.MaxWeaponDamage*2.5)) ) --50 damage
								dmginfo:SetDamageType( DMG_DROWN ) --Bullet damage
								dmginfo:SetAttacker( pl ) --First player found gets credit
								dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) ) --Launch upwards
							target:TakeDamageInfo( dmginfo ) 
							target.Speed = true 
							target.SpeedMod = -1
							target.SpeedModDuration = 3
							target.SpeedType = "Charge"
						end)
					end
				end
			end)
			timer.Simple(0.2, function()
				pl.InSpellAnimation = false
				pl:SetNWBool("Casting", false)
				pl:SetNWBool("Casted", false)
			end)
		end)
	end
end



